package com.hanggold.rc.demo;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/**
 * TODO COMMENT.
 *
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-08-18 15:53
 * @since 1.0.0
 **/
public class CommandCliDemo {
    
    public static void main(String[] args) throws ParseException {
        DefaultParser defaultParser = new DefaultParser();
        CommandLine commandLine = defaultParser.parse(getOptions(), args);
        String[] args1 = commandLine.getArgs();
        help();
        System.out.println("n: " + commandLine.getOptionValue("n"));
    }
    
    public static void help() {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("appName", getOptions(), true);
    }
    
    public static Options getOptions() {
        Options options = new Options();
        
        Option option = new Option("c", true, "测试1");
        option.setRequired(true);
        Option option2 = new Option("n", true, "测试12");
        option2.setRequired(true);
        options.addOption(option).addOption(option2);
        return options;
    }
}
